/**
 * 用户相关状态数据
 *
 * @author 济南晨霜信息技术有限公司
 * @mobile 18560000860 / 18754137913
 */
import { ref, computed } from "vue";
import { defineStore } from "pinia";
import persistCommonConfig from "@/stores/persist-common-config";

// 定义状态数据
export const useUserStore = defineStore(
    "user",
    () => {
        // 用户信息
        const userinfo = ref(null);

        // 用户登录状态
        const loginStatus = computed(() => {
            return !!userinfo.value;
        });

        /**
         * 清空用户状态数据
         */
        function clear() {
            userinfo.value = null;
        }

        return {
            userinfo,
            loginStatus,
            clear
        };
    },
    {
        // pinia-plugin-persistedstate 插件配置
        persist: persistCommonConfig
    }
);
